# dark dimension intro
(class dd_world_main dd_world
	(group

	# tracking timing
	(def float counter)
	(def int positive)
	(def int delay)

	# dark dimension logo
	(def dd_meshColour logo)

	(def dd_sound sound)
	(def int soundPlayed)

	(def float scale)

	# constractor
	(function create (group)
		(group

		# initialise animation values
		(dd_clearColour 0 0 0 1)
		(= this.counter 0)
		(= this.positive 1)
		(= this.delay 30)

		# initialise dd logo
		(dd_meshColour_create this.logo)
		(this.logo.load "logo.ply")
		(this.logo.set_colour 0 0 0)

		(dd_sound_create this.sound)
		(this.sound.load "dd_theme.wav" 0)
		(= this.soundPlayed 0)

		(= this.scale 1)

		)
	)

	(function resize (group)
		(group

		(def float height)
		(= height (/ (dd_screen_height_get 5) 3.5)) # 3.0 = height of logo
		(def float width)
		(= width (/ (dd_screen_width_get 5) 6.3)) # 6.3 = width of logo

		(if (< width height)
			(= this.scale width)
		# else
			(= this.scale height)
		)

		)
	)

	# update - update animations
	(function update (group)
		(group

		# on delay do nothing
		(if (> this.delay 0)
			(= this.delay (- this.delay 1))

		# else
			(group

			# update clear colour
			(dd_clearColour (* this.counter 0.8) (* this.counter 0.6) (* this.counter 1) 1)

			# advance animation
			(if this.positive
				(group
				(= this.counter (+ this.counter 0.01))

				(if (&& (> this.counter 0.25) (== this.soundPlayed 0))
					(group
					(this.sound.play)
					(= this.soundPlayed 1)
					)
				)
				(if (>= this.counter 1)
					(group
					(= this.counter 1)
					(= this.positive 0)
					(= this.delay 120)
					)
				)
				)
				(group
				(= this.counter (- this.counter 0.01))
				(if (<= this.counter 0)
					(group
					(= this.counter 0)
					(dd_world_set dd_world_menu)
					(def (ref dd_world_menu) cmenu cworld)
					(= cmenu.fromIntro 1)
					(dd_clearColour 0 0 0 1)
					)
				)
				)
			)
			)
		) # if delay

		)
	)

	# draw
	# zoom-out so the world is visible
	# rotate the world
	# draw the cube
	(function draw (group)
		(group
		(glTranslatef 0 0 -5)
		(glScalef this.scale this.scale this.scale)
		(this.logo.draw)
		)
	)

	(function key_input (group char key)
		(group
		)
	)

	(function clean (group)
		(group
		(this.sound.clean)
		(this.logo.clean)
		(dd_world_clean this)
		)
	)

	)
) # main world
